package model;

import java.util.ArrayList;

/**
 * Publicly accessible struct representing a stack of cards on the table. 
 * This is to be used only in TableModel.
 * These stacks are not to be used for player's hands. Use the PlayerHand class instead for that.
 */
public class CardStack {
	/** Contents of the stack */
	private ArrayList<Card> cards;
	/** x coordinate of center of the bottom card on the stack */
	private int x;
	/** y coordinate of center of the bottom card on the stack */
	private int y;
	/** face up? */
	private boolean faceUp;
	
	public CardStack(int x, int y) {
		this.cards = new ArrayList<Card>();
		this.x=x;
		this.y=y;
		this.faceUp = true;
	}
	public CardStack(int x, int y, boolean faceUp) {
		this.cards = new ArrayList<Card>();
		this.x=x;
		this.y=y;
		this.faceUp = faceUp;
	}
	public int getX() {
		return x;
	}
	public void setXY(int x, int y) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public boolean getFaceUp() {
		return faceUp;
	}
	
	public int size()
	{
		return cards.size();
	}
	
	public void push(Card c)
	{
		cards.add(c);
	}
	
	public Card pop()
	{
		return cards.remove(cards.size() -1);
	}
	
	public ArrayList<Card> getCards()
	{
		return cards;
	}
	
	public void flip() {
		faceUp = !faceUp;
	}
	public void setFaceUp(boolean b) {
		faceUp = b;
	}
	
	public String toMessage()
	{
		
		StringBuffer sb = new StringBuffer().append("cardstack%").
					append(x).append("#").append(y).append("#").append(faceUp).
					append("#").append("[");
	
		if (cards.size() > 0)
		{

			for (int i = 0; i < cards.size()-1; i++)
			{
				sb.append(cards.get(i)).append(",");
			}
			
			sb.append(cards.get(cards.size()-1).toString());
		}

		sb.append("]");
		
		return sb.toString();
	}
	
}
